<template>
  <div class="loginbk">
    <el-form style="bottom:30%;" :model="ruleForm2" :rules="rules2" ref="ruleForm2" label-position="left" label-width="0px" class="demo-ruleForm login-container">
      <h3 class="title">登录自营平台管理系统</h3>
      <el-form-item prop="account">
        <el-input type="text" icon="menu" v-model="ruleForm2.account" auto-complete="off" placeholder="账号"></el-input>
      </el-form-item>
      <el-form-item prop="checkPass">
        <el-input type="password" icon="setting" v-model="ruleForm2.checkPass" auto-complete="off" placeholder="密码"></el-input>
      </el-form-item>
      <el-form-item prop="imgCode">
        <el-col :xs="10" :sm="10" :md="10" :lg="10">
          <el-input v-model="ruleForm2.imgCode" auto-complete="off" placeholder="图形码" ></el-input>
        </el-col>
        <el-col :xs="6" :sm="6" :md="6" :lg="6">
        <div data-v-369deb1d="" class="img__code--change" @click="changeImgCode()">换一张</div>
        </el-col>
        <el-col :xs="8" :sm="8" :md="8" :lg="8">
          <img :src="imgCodeSrc" alt="" class="img__code" @click="changeImgCode()">
        </el-col>
      </el-form-item>
      <!--<el-checkbox v-model="checked" checked class="remember">记住密码</el-checkbox>-->
      <el-form-item style="width:100%;">
        <el-button type="primary" style="width:100%;" icon="caret-right" @click.native.prevent="handleSubmit2" :loading="logining">登录</el-button>
        <!--<el-button @click.native.prevent="handleReset2">重置</el-button>-->
      </el-form-item>
    </el-form>
    <div class="signup-footer">
      <div class="l_footer">
        <p>恒华保险</p>
        <p>Copyright © 2016 | 渝ICP备11007172号 </p>
      </div>
    </div>
  </div>
</template>

<script>
//import NProgress from 'nprogress'
import login from 'js/login';
export default {
  data() {

    var imgCode = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('图形码不能为空'));
      }
      else {
        if (!(/^[0-9a-zA-Z]{4}$/.test(value))) {
          return callback(new Error('请输入正确的图形码'));
        } else {
          return callback();
        }
      }
    };

    return {
      logining: false,
      imgCodeSrc:location.protocol + "//" + location.hostname+"/cxb/nol/code/getImgCode", //验证码图片路径
      ruleForm2: {
        account: '',
        checkPass: '',
        imgCode:''
      },
      rules2: {
        account: [
          { required: true, message: '请输入账号', trigger: 'blur' },
          //{ validator: validaePass }
        ],
        checkPass: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          //{ validator: validaePass2 }
        ],
        imgCode: [
          { required: true, validator: imgCode, trigger: 'blur' },
          //{ validator: validaePass2 }
        ]
      },
      checked: true
    };
  },
  methods: {
    //更换图形码
    changeImgCode() {
      this.imgCodeSrc = location.protocol + "//" + location.hostname+"/cxb/nol/code/getImgCode?a=" + Math.random();
    },
    handleReset2() {
      this.$refs.ruleForm2.resetFields();
    },
    handleSubmit2(ev) {
      var _this = this;
      login.login(_this);
    }
  },
  mounted() {
    // debugger
                    let WEB_DOMAIN_FULL_PATH = window.location.protocol + "//" + window.location.hostname + "/admin-cxb/#/login";
                    console.log(WEB_DOMAIN_FULL_PATH);
    let _this = this;
    document.onkeydown = function (event) {
      let e = event ? event : (window.event ? window.event : null);
      if (e.keyCode == 13) {
        //执行的方法
        login.login(_this);
        return false;
      }
    };
  }
}

</script>

<style lang="scss" scoped>
@import "~styles/Login";
</style>
